package cn.edu.lzu.unitweb.controller;

import cn.edu.lzu.common.assist.DataPage;
import cn.edu.lzu.common.assist.ResponseResult;
import cn.edu.lzu.entity.ClinicExamineItem;
import cn.edu.lzu.entity.ExamineItem;
import cn.edu.lzu.entity.Examiner;
import cn.edu.lzu.service.ClinicExamineItemService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.support.DefaultSubjectContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.security.Principal;
import java.util.List;

/**
 * @PackageName: cn.edu.lzu.unitweb.controller
 * @ClassName: ClinicExamineItemController
 * @Description: TODO
 * @Author: 张琦[QQ:3098086691]
 * @Date: 2020/3/29 18:30
 * @Version: 1.0
 */
@Controller
public class ClinicExamineItemController {
    @Resource
    private ClinicExamineItemService clinicExamineItemService;

    @ResponseBody
    @RequestMapping("/getCliExamineItems")
    public DataPage getCliExamineItems(int currentPageNum, int pageSize){
        Session session= SecurityUtils.getSubject().getSession();
        Examiner examiner=(Examiner)((PrincipalCollection)session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY)).getPrimaryPrincipal();
        DataPage dataPage=clinicExamineItemService.getCliExamineItems(examiner.getUnitId(), currentPageNum, pageSize);
        return dataPage;
    }

    @ResponseBody
    @RequestMapping("/deleteCliItemById")
    public ResponseResult deleteCliItemById(Integer examineItemId){
        ResponseResult responseResult=clinicExamineItemService.deleteCliItemById(examineItemId);
        return responseResult;
    }

    @ResponseBody
    @RequestMapping("/submitAddCliExamineItem")
    public ResponseResult submitAddCliExamineItem(ClinicExamineItem clinicExamineItem){
        Session session= SecurityUtils.getSubject().getSession();
        Examiner examiner=(Examiner)((PrincipalCollection)session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY)).getPrimaryPrincipal();
        clinicExamineItem.setUnitId(examiner.getUnitId());
        ResponseResult responseResult=clinicExamineItemService.addCliItem(clinicExamineItem);
        return responseResult;
    }

    @ResponseBody
    @RequestMapping("/getAllCliItems")
    public List<ClinicExamineItem> getAllCliItems(){
        Session session= SecurityUtils.getSubject().getSession();
        Examiner examiner=(Examiner)((PrincipalCollection)session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY)).getPrimaryPrincipal();
        List<ClinicExamineItem> clinicExamineItemList=clinicExamineItemService.getAllCliItems(examiner.getUnitId());
        return clinicExamineItemList;
    }

}
